//author:jxx
import store from "@/store/index";
//此处是对表单的方法，组件，权限操作按钮等进行任意扩展(方法扩展可参照SellOrder.js)
let extension = {
    components: {
        //动态扩充组件或组件路径
        //表单header、content、footer对应位置扩充的组件
        gridHeader: "", //{ template: "<div>扩展组xx件</div>" },
        gridBody: "",
        gridFooter: "",
        //弹出框(修改、编辑、查看)header、content、footer对应位置扩充的组件
        modelHeader: "",
        modelBody: "",
        modelFooter: ""
    },
    buttons: { view: [], box: [], detail: [] }, //扩展的按钮
    methods: {
        //事件扩展
        getOption(field) {
            let option;
            this.editFormOptions.forEach(x => {
                x.forEach(item => {
                    if (item.field == field) {
                        option = item;
                    }
                });
            });
            return option;
        },
        onInit() {
            //新建窗口的宽和高
            this.boxOptions.width = 1000;
            this.boxOptions.height = 400;
        },

        direct() {
            // 没用上
        },
        async modelOpenBeforeAsync(row) {
            return true;
        },
        rowClick({ row, column, event }) {
            //查询界面table点击行选中当前行
            console.log(row);
            this.$refs.table.$refs.table.toggleRowSelection(row);
            return true;
        },
        delBefore(ids, rows) {
            console.log(rows, "rows");
            let code = rows.map(i => i.supplierCode);
            let params = {
                page: 1,
                rows: 30,
                sort: "createDate",
                order: "desc",
                wheres: `[{\"name\":\"supplierCode\",\"value\":\"${code.join(
                    ","
                )}\",\"displayType\":\"checkbox\"}]`
            };
            this.http.post("api/Products/getPageData", params).then(res => {
                if (res.rows.length != 0) {
                    this.$Message.error("当前采购供应下有产品，暂时不能删除");
                } else {
                    this.$Modal.confirm({
                        title: "删除警告!",
                        content:
                            '<p style="color: red;font-weight: bold;letter-spacing: 3px;">确认要删除选择的数据吗?</p>',
                        onOk: () => {
                            this.http.post("api/SupplierNews/del", ids).then(res => {
                                this.$Message.success("删除成功");
                                this.refresh();
                            });
                        }
                    });
                }
            });
        },
        modelOpenAfter(row) {
        },
        addBefore(formData) {
            //新建保存前formData为对象，包括明细表
            return this.veriFromTable(formData, 1);
        },
        updateBefore(formData) {
            //编辑保存前formData为对象，包括明细表、删除行的Id
            return this.veriFromTable(formData, 2);
        },
        // 保存前编辑
        veriFromTable(formData, flag) {
            formData.detailData = [];
            formData.mainData.supplierSystem = 1;
            formData.mainData.isDebug = 0;
            formData.mainData.isDelete = 0;
            formData.mainData.SupplierType = formData.mainData.SupplierType1;
            if (flag == 1) {
                formData.mainData.merchantName = '';
                formData.mainData.merchantCode = '';
            }
            console.log(formData, 'formData');
            return true;
        },
    }
};
export default extension;
